package com.xiyue.leaspring.util.dbc;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class RedisConnectionUtil2 {

	private static final String REDIS_HOST = "127.0.0.1";
	private static final int REDIS_PORT = 6379;
	private static final int TIME_OUT = 2000;
	private static final int MAX_TOTAL = 200;
	private static final int MAX_IDLE = 20;
	private static final int MAX_WAIT_MILLIS = 1000;
	private static final boolean TEST_ON_BORROW = true;
	private JedisPool jedisPool;
	
	public RedisConnectionUtil2() {
		JedisPoolConfig config = new JedisPoolConfig();
		config.setMaxTotal(MAX_TOTAL);
		config.setMaxIdle(MAX_IDLE);
		config.setMaxWaitMillis(MAX_WAIT_MILLIS);
		config.setTestOnBorrow(TEST_ON_BORROW);
		this.jedisPool = new JedisPool(config, REDIS_HOST,REDIS_PORT,TIME_OUT);
	}
	
	public void close() {
		this.jedisPool.close();
	}
	
	public Jedis getConnection() {
		return this.jedisPool.getResource();
	}
	
}
